{% template "admin/header.html" %}
<div class="admin-main">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>编辑权限</legend>
    </fieldset>
    <blockquote class="layui-elem-quote">
        1、《控/方》：意思是 /控制器/方法; 例如 /Sys/sysList<br/>
        2、图标名称为左侧导航栏目的图标样式，具体可查看<a href="https://icomoon.io/app/#/select" target="_blank">premium</a>图标
    </blockquote>
    <form class="layui-form layui-form-pane" lay-filter="form">
        <input type="hidden" name="id" value="">
        <div class="layui-form-item">
            <label class="layui-form-label">权限名称</label>
            <div class="layui-input-4">
                <input type="text" name="title" value="" lay-verify="required" placeholder="权限名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">路由</label>
            <div class="layui-input-4">
                <input type="text" name="href" value="" lay-verify="required" placeholder="控制器/方法" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图标名称</label>
            <div class="layui-input-4">
                <input type="text" name="icon" value="" placeholder="图标名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单状态</label>
            <div class="layui-input-block">
                <input type="radio" name="menustatus"  value="1" title="开启" >
                <input type="radio" name="menustatus" value="0" title="关闭">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单</label>
            <div class="layui-input-block">
                <input type="radio" name="is_menu"  value="1" title="是" >
                <input type="radio" name="is_menu"  value="0" title="否">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-2">
                <input type="text" name="sort" value="" placeholder="排序编号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="auth">立即提交</button>
                <a href="javascript:window.history.back();" class="layui-btn layui-btn-primary">返回</a>
            </div>
        </div>
    </form>
</div>
{% template "admin/footer.html" %}
<script>
    let id = getUrlParam("id");
    layui.use(['form', 'layer'], function () {
        var form = layui.form,layer = layui.layer,$ = layui.jquery;

        $.post('/admin/menu/get',{id:id},function (data) {
            let formdata = upperJSONKey(data.Data);
            form.val('form',formdata);
            $('input[name="is_menu"][value="'+formdata.is_menu+'"]').attr('checked',true);
            $('input[name="menustatus"][value="'+formdata.menustatus+'"]').prop('checked',true);
            form.render();
        });

        form.on('submit(auth)', function (data) {
            // 提交到方法 默认为本身
            $.post("/admin/menu/edit",data.field,function(res){
                if(res.Code > 0){
                    layer.msg(res.Msg,{time:1800,icon:1},function(){
                        window.history.back();
                    });
                }else{
                    layer.msg(res.Msg,{time:1800,icon:2});
                }
            });
        })
    })
</script>
</body>
</html>